<template>
	<view class="">
		<view class="is-bg-blue">
			<view class="has-pdt-25 has-pdlr-20 is-size-25 is-white">
				<text>您未领取的佣金</text>
			</view>
			<view class="has-pdb-25 has-pdlr-20 is-size-20 is-white">
				<view class="is-right">{{agent_num}}DC</view>
			</view>
		</view>
		
		<view class="bankbox">
			<view class="is-blod has-pdb-8">
				截止当前
			</view>
			<view class="s-row has-pdtb-4">
				<view class="is-col-8 is-grey">
					已领
				</view>
				<view class="is-col-16 is-right">
					{{ok_agent_num}}DC
				</view>
			</view>
			<view class="s-row has-pdtb-4">
				<view class="is-col-8 is-grey">
					未领
				</view>
				<view class="is-col-16 is-right">
					{{no_agent_num}}DC
				</view>
			</view>
		</view>
		<view class="has-pdlr-10 has-pdt-15" v-show="no_agent_num > 0">
			<button @click="incomeok" type="primary">确定领取我的佣金</button>
		</view>
		<view>
		    <show-modal></show-modal>
		</view>
	</view>
</template>

<script>
	var _self;
	export default {
		data() {
			return {
				foxtoken:'',
				agent_num:0,
				no_agent_num:0,
				ok_agent_num:0
			}
		},
		onLoad() {
			_self = this;
			this.get_agent();
		},
		methods:{
			get_agent(){
				let info = this.service.getfox();
				if(info[0]){
					this.foxtoken = info[0]['foxtoken'];
					uni.request({
						url: this.service.FOX_URL + 'diamond/get_agent_income',
						method:'POST',
						data: {
							user_key:this.foxtoken
						},
						dataType:'json',
						header:{
							'content-type':'application/x-www-form-urlencoded'
						},
						success: res => {    
							var foxmsg = res.data;
							// console.log(foxmsg)
							if (foxmsg.code == 200) {  
								_self.agent_num = foxmsg.data.list.agent_num;
								_self.no_agent_num = foxmsg.data.list.no_agent_num;
								_self.ok_agent_num = foxmsg.data.list.ok_agent_num;
							}
						}                    
					});
				}else{
					uni.reLaunch({
						url:'../logon/login'
					})
				}
			},
			incomeok(){
				this.$showModal({
				    title: '提示',
				    content: '一旦操作无法回退，您确定要领取佣金么？',
					cancelText:'放弃',
					confirmText:'是的，我要领取',
				    success: function (res) {
				        if (res.confirm) {
				            uni.request({
				            	url: _self.service.FOX_URL + 'diamond/agent_incomeok',
				            	method:'POST',
				            	data: {
				            		user_key: _self.foxtoken,
				            	},
				            	dataType:'json',
				            	header:{
				            		'content-type':'application/x-www-form-urlencoded',
				            	},
				            	success: res => {
				            		var rest = res.data;
									console.log(rest)
				            		if(rest.status == 'success'){
				            			uni.showToast({
				            				title:rest.msg,
				            				icon:'none',
				            				mask:true
				            			})
										setTimeout(function() {
										    uni.navigateTo({
										    	url:'../index/index'
										    })
										}, 1500)
				            		}else{
				            			uni.showToast({
				            				title:rest.msg,
				            				icon:'none',
				            				mask:true
				            			})
				            		}
				            	}
				            })
				        }
				    }
				});
			}
		}
	}
</script>

<style>
	.do-top{
		background-color: #007AFF;
		color:#fff;
		padding:20rpx 0;
	}
	.clockbox {margin:8upx;background:#F0AD4E;width:52upx;height: 52upx;border-radius: 100%;}
	.orderbox{
		padding:20upx;
		border-bottom: 16upx solid #F0F0F0;
	}
	.bankbox{
		padding:20upx;
		border-bottom: 6upx solid #F0F0F0;
	}
</style>
